package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.CheckItem;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

public interface checkItemMapper {

    @Insert("insert into t_checkitem(code,name,sex,age,price,type,remark,attention) values (#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})")
    public void addCheckItem(CheckItem checkItem);

    /*
     select * from t_checkitem
     <where>
        <if test="queryString !=null and queryString.length > 0">
          code  = #{queryString} or name like concat('%',#{queryString},'%')
          </if>
     </where>
     */

    @Select("<script> select * from t_member\n" +
            "     <where>\n" +
            "        <if test=\"queryString !=null and queryString.length > 0\">\n" +
            "          code  = #{queryString} or name like concat('%',#{queryString},'%')\n" +
            "          </if>\n" +
            "     </where></script>")
    Page<CheckItem> findPage(@Param("queryString") String queryString);


    @Select("SELECT COUNT(*) FROM t_checkgroup_checkitem  WHERE checkitem_id=#{id};")
    Long findGroupByCheckitem4Id(Integer id);

    @Delete("DELETE  FROM t_checkitem WHERE id=#{id};")
    void delectCheckItemById(int id);

    @Select("SELECT * FROM t_checkitem WHERE id =#{id}")
    CheckItem findCheckitemByid(Integer id);


    /*
       private Integer id;//主键
        private String code;//项目编码
        private String name;//项目名称
        private String sex;//适用性别
        private String age;//适用年龄（范围），例如：20-50
        private Float price;//价格
        private String type;//检查项类型，分为检查和检验两种类型
        private String remark;//项目说明
        private String attention;//注意事项
    * */
    /*
    UPDATE t_checkitem
    <set>
       <if test="name != null">
       name = #{name},
       </if>
       <if test="sex != null">
       sex = #{sex},
       </if>
       <if test="code != null">
       code = #{code},
       </if>
       <if test="age != null">
       age = #{age},
       </if>
       <if test="price != null">
       price = #{price},
       </if>
       <if test="type != null">
       type = #{type},
       </if>
       <if test="attention != null">
       attention = #{attention},
       </if>
       <if test="remark != null">
       remark = #{remark},
       </if>
       where id = #{id}
    </set>

    */
    @Update("<script>" +
            "update t_checkitem\n" +
            "        <set>\n" +
            "            <if test=\"name != null\">\n" +
            "                name = #{name},\n" +
            "            </if>\n" +
            "            <if test=\"sex != null\">\n" +
            "                sex = #{sex},\n" +
            "            </if>\n" +
            "            <if test=\"code != null\">\n" +
            "                code = #{code},\n" +
            "            </if>\n" +
            "            <if test=\"age != null\">\n" +
            "                age = #{age},\n" +
            "            </if>\n" +
            "            <if test=\"price != null\">\n" +
            "                price = #{price},\n" +
            "            </if>\n" +
            "            <if test=\"type != null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"attention != null\">\n" +
            "                attention = #{attention},\n" +
            "            </if>\n" +
            "            <if test=\"remark != null\">\n" +
            "                remark = #{remark},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}" +
            "</script>")
    Long updataCheckitem(CheckItem checkItem);
}
